import * as path from 'node:path'
import { isVue2 } from "vue-demi";
import { defineConfig } from "vite";

export const baseBuildConfig = defineConfig({
  build: {
    emptyOutDir: false,
    outDir: path.resolve(__dirname, `../dist/${isVue2 ? "v2" : "v3"}`),
    target: "es2018",
    lib: {
      name: "JmVueDirective",
      fileName: (format) => `jm-vue-directive.${format}.js`,
    },
    rollupOptions: {
      external: ["vue", "@vue/composition-api/dist/vue-composition-api.mjs"],
      output: {
        globals: {
          vue: "Vue",
          "@vue/composition-api/dist/vue-composition-api.mjs":
            "VueCompositionAPI",
        },
      },
    },
  },
  optimizeDeps: {
    exclude: ["vue-demi", "vue", "vue2"],
  },
});
